package com.fourth.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fourth.dao.HeadNavDao;
import com.fourth.service.HeadNavService;
import com.ljx.entity.HeadNav;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：lmy
 * @Date：2023/2/27 15:31
 */
@Api(value = "home/api/headNav", tags = {""})
@RestController
@RequestMapping("home/api/headNav")
public class ApiHeadNavController {
    @Autowired
    private HeadNavService headNavService;
    @Autowired(required = false)
    private HeadNavDao headNavDao;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "HeadNav", name = "headNav", value = "", required = true)
    })
    @ApiOperation(value = "分页查询", notes = "", httpMethod = "POST")
    @PostMapping  ("fuzzySearch")
    public Result FuzzySearch(@RequestParam(defaultValue = "1")Integer currentPage,
                              @RequestParam(defaultValue = "5")Integer pageSize,
                              @RequestBody HeadNav headNav){
        return headNavService.fuzzySearch(currentPage,pageSize,headNav);
    }
    @GetMapping("updateDisable/{headId}/{isDisable}")
    public Result updateDisable(@PathVariable Integer headId,@PathVariable String isDisable){
        HeadNav headNav = new HeadNav();
        headNav.setHeadId(headId);
        headNav.setIsDisable(isDisable);
        int row = headNavDao.updateById(headNav);
        if (row == 1){
            return new Result(2000,"修改成功");
        }
        return  new Result(5000,"修改失败");
    }

    @PostMapping("insertNavigation")
    public Result insertNavigation(@RequestBody HeadNav headNav){
        int row = headNavDao.insert(headNav);
        if (row ==1 ){
            return new Result(2000,"添加成功");
        }
        return new Result(5000,"添加失败");
    }

    @PostMapping("updateNavigation")
    public Result updateNavigation(@RequestBody HeadNav headNav){
        int row = headNavDao.updateById(headNav);
        if (row == 1 ){
            return new Result(2000,"修改成功");
        }
        return new Result(2000,"修改失败");
    }

    @GetMapping("removeNavigation")
    public Result removeNavigation(@RequestParam Integer headId){
        HeadNav headNav = new HeadNav();
        headNav.setHeadId(headId);
        headNav.setIsDeleted("1");
        int row = headNavDao.updateById(headNav);
        if (row == 1){
            return new Result<>(2000,"删除成功");
        }
        return new Result(5000,"删除失败");
    }
}
